using Fusion.Utilities.Singleton;
using UnityEngine;

namespace Fusion.Frameworks.Performance
{
    public class PerformanceManager : SingletonBehaviour<PerformanceManager>
    {
        private int fps = 0;
        private int totalFrame = 0;
        private float deltaTime = 0.0f;

        private float frameUpdateFrequency = 0.1f;

        public float FrameUpdateFrequency { get => frameUpdateFrequency; set => frameUpdateFrequency = value; }
        public int FPS { get => fps; }

        // Update is called once per frame
        void Update()
        {
            totalFrame++;
            deltaTime += Time.unscaledDeltaTime;
            if (deltaTime > frameUpdateFrequency)
            {
                fps = Mathf.CeilToInt(totalFrame / deltaTime);
                totalFrame = 0;
                deltaTime -= frameUpdateFrequency;
            }
        }
    }
}

